class AddProgress < ActiveRecord::Migration
  def self.up
    add_column :tasks, :progress, :integer, :default=>0
    Task.find(:all).each { |t|
      case t.done
        when 0
          if t.begun == 1
            t.progress = 1
          else
            t.progress = 0
          end
        when 1
          t.progress = 2
        else
          t.progress = 0
      end
      t.save
      }
    remove_column :tasks, :begun
  end

  def self.down
    add_column :tasks, :begun, :integer, :default=>0
    Task.find(:all).each { |t|
      if t.progress == 1
        t.begun = 1
        t.save
      end  
      }
    remove_column :tasks, :progress
  end
end

